package com.ggh.jinjilive.ui.mine.personal;

import androidx.databinding.ObservableField;
import androidx.lifecycle.MutableLiveData;

import com.ggh.jinjilive.mobile.ResultEntity;
import com.ggh.jinjilive.mobile.create.StartLiveMobile;
import com.ggh.jinjilive.mobile.mine.personal.PersonalDataMobile;
import com.ggh.jinjilive.mobile.mine.video.PersonalVideoList;
import com.ggh.jinjilive.mobile.social.near.NearUser;
import com.ggh.jinjilive.remotedata.InterceptObserver;
import com.ggh.jinjilive.remotedata.systemapi.SystemApiService;
import com.ggh.jinjilive.ui.BaseViewModel;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

public class PersonalDataViewModel extends BaseViewModel {
    //接口获取的个人资料
    public MutableLiveData<PersonalDataMobile> mPersonalDataMobile = new MutableLiveData<>();
    //获取当前用户发布的视频
    public MutableLiveData<List<PersonalVideoList>> mPersonalVideoList = new MutableLiveData<>();

    public PersonalDataViewModel(SystemApiService apiCallInterface) {
        super(apiCallInterface);


    }


    /**
     * 获取个人资料
     */
    public void videoAnchorView(int anchor_id){
        Map<String, Object> map = new HashMap<>();
        map.put("anchor_id",anchor_id);
        addSubscribe(apiCallInterface.videoAnchorView(map).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribeWith(new InterceptObserver<ResultEntity<PersonalDataMobile>>() {
            @Override
            public void onNextData(ResultEntity resultEntity) {
                PersonalDataMobile personalDataMobile = (PersonalDataMobile) resultEntity.getData();
                mPersonalDataMobile.setValue(personalDataMobile);
            }

            @Override
            public void onErrorNet(Throwable t, String netMsg) {

            }
        }));
    }

    /**
     * 关注
     */
    public void myFollow(int be_user_id){
        Map<String, Object> map = new HashMap<>();
        map.put("be_user_id",be_user_id);
        addSubscribe(apiCallInterface.myFollow(map).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribeWith(new InterceptObserver<ResultEntity<PersonalDataMobile>>() {
            @Override
            public void onNextData(ResultEntity resultEntity) {
                videoAnchorView(be_user_id);
            }

            @Override
            public void onErrorNet(Throwable t, String netMsg) {

            }
        }));
    }

    /**
     * 获取当前用户发布的视频
     * @param user_id
     */
    public void infoVideoList(int user_id){
        if (isRefresh) {
            page = 1;
        }else {
            page = page + 1;
        }
        Map<String, Object> map = new HashMap<>();
        map.put("user_id",user_id);
        map.put("page",page);
        map.put("limit",pageSize);
        addSubscribe(apiCallInterface.infoVideoList(map).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribeWith(new InterceptObserver<ResultEntity<List<PersonalVideoList>>>() {
            @Override
            public void onNextData(ResultEntity resultEntity) {
                List<PersonalVideoList> personalVideoListList = (List<PersonalVideoList>) resultEntity.getData();
                mPersonalVideoList.setValue(personalVideoListList);
            }

            @Override
            public void onErrorNet(Throwable t, String netMsg) {

            }
        }));
    }


}
